import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wan_android_flutter/common/base/base_page.dart';
import 'package:wan_android_flutter/common/resources/text_styles.dart';
import 'package:wan_android_flutter/modules/main/knowledge_system/single_knowledge_system/single_knowledge/single_knowledge_logic.dart';
import 'package:wan_android_flutter/modules/main/knowledge_system/single_knowledge_system/single_knowledge/single_knowledge_page.dart';

import 'single_knowledge_system_logic.dart';

class SingleKnowledgeSystemPage extends BasePage<SingleKnowledgeSystemLogic> {
  SingleKnowledgeSystemPage({super.key});

  @override
  Widget? buildTitleWidget() {
    return Obx(() {
      return Text(
        logic.state.title.value,
        style: colorData.textBlack.s18.regular,
      );
    });
  }

  @override
  Widget buildContent(BuildContext context) {
    return Obx(() {
      return Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            color: colorData.bgWhite,
            height: 60,
            child: TabBar(
              indicator: const BoxDecoration(),
              tabAlignment: TabAlignment.start,
              isScrollable: true,
              controller: logic.tabController,
              tabs: logic.state.tabLocalKeyList.map((element) {
                return Obx(() {
                  return Text(
                    element,
                    style: logic.state.currentTabIndex.value ==
                            logic.state.tabLocalKeyList.indexOf(element)
                        ? colorData.textBlue.s16.regular
                        : colorData.textBlack.s16.regular,
                  );
                });
              }).toList(),
              // margin: const EdgeInsets.symmetric(horizontal: 0),
            ),
          ),
          const Divider(
            height: 1,
            thickness: 0.5,
            color: Colors.grey,
          ),
          Expanded(
              child: TabBarView(
            controller: logic.tabController,
            children: logic.state.knowledges.map((element) {
              Get.put(SingleKnowledgeLogic(model: element), tag: element.name ?? "");
              return SingleKnowledgePage(element);
            }).toList(),
          )),
        ],
      );
    });
  }
}
